package ywpt.service.config;

import ywpt.core.dao.extend.HibernateEntityExtendDao;
import ywpt.model.CommonTable;
import ywpt.model.ProjectInfo;
import ywpt.model.ProjectPeople;

public class ProjectPeopleServiceImpl extends HibernateEntityExtendDao<ProjectPeople> implements ProjectPeopleService{

	@Override
	public ProjectPeople getProjectPeopleById(Long id) {
		return this.get(id);
	}

	@Override
	public void removeProjectPeople(Long id) {
		this.removeById(id);
	}

	@Override
	public void saveProjectPeople(ProjectPeople projectPeople, Long projectId,
			Long postId, String[] peoId) {
		if (projectId!=null) 
		projectPeople.setProject(this.get(ProjectInfo.class, projectId));
		if (postId!=null) 
		projectPeople.setPost(this.get(CommonTable.class, postId));
		if (peoId.length>0) {
			String str ="";
			for (int i = 0; i < peoId.length; i++) {
				str = str+peoId[i]+",";
			}
			projectPeople.setPeoStr(str);
		}
		this.save(projectPeople);
	}

	@Override
	public void updateProjectPeople(ProjectPeople projectPeople, Long postId,
			String[] peoId) {
		if (postId!=null) 
			projectPeople.setPost(this.get(CommonTable.class, postId));
		if (peoId.length>0) {
			String str ="";
			for (int i = 0; i < peoId.length; i++) {
				str = str+peoId[i]+",";
			}
			projectPeople.setPeoStr(str);
		}
		this.update(projectPeople);
	}

}
